package com.qfedu.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qfedu.common.JsonResult;
import com.qfedu.dao.EmployeeDao;
import com.qfedu.pojo.Employee;
import com.qfedu.pojo.VEmployee;
import com.qfedu.service.EmployeeDaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class EmployeeDaoServiceImpl implements EmployeeDaoService {
    @Autowired
    private EmployeeDao employeeDao;
    @Override
    public List<Employee> findAll(VEmployee employee,int page, int limit) {
        PageHelper.startPage(page,limit);
       return employeeDao.findAll(employee);
    }

    @Override
    public Employee selectById(Integer id) {

        return employeeDao.selectById(id);
    }

    @Override
    public void deleteById(Integer id) {
        Employee employee = employeeDao.selectById(id);
        if (employee != null) {
            employeeDao.deleteById(id);
        } else {
            throw new RuntimeException("该员工id不存在");
        }
    }

    @Override
    public void add(VEmployee vEmployee) {
        Employee employee = employeeDao.selectByCid(vEmployee.getCardId());
        System.out.println(employee);
        if (employee == null) {
            employeeDao.add(vEmployee);
        }else {
            throw new RuntimeException("身份证号码已存在");
        }
    }

    @Override
    public VEmployee selectByEId(Integer id) {
        return employeeDao.selectByEId(id);
    }

    @Override
    public void updateEmployee(VEmployee vEmployee) {
        employeeDao.updateEmployee(vEmployee);
    }
}
